package com.yang.springcloud.service.impl;

import com.yang.springcloud.pojo.Dept;
import com.yang.springcloud.service.DeptClientServer;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author shiwen
 * @date 2021/2/7
 */

// 仅用于进行降级的
@Component
public class DeptClientServiceFallbackFactory implements FallbackFactory {

    @Override
    public DeptClientServer create(Throwable throwable) {
        // 这里直接创建子类, 当service层失败了则直接返回子类里面的对象
        return new DeptClientServer() {
            @Override
            public Dept queryById(Long id) {
                return new Dept()
                        .setDeptNo(id)
                        .setDeptName("没有对应的信息, 客户端提供了降级的信息, 服务已经被关闭" + id + "")
                        .setDbSource("not exists MySQL");
            }

            @Override
            public List<Dept> queryAll() {
                return null;
            }

            @Override
            public boolean addDepe(Dept dept) {
                return false;
            }
        };
    }

}